package com.csdj.socket_thread;

import java.io.*;
import java.net.Socket;

public class ServerScoketThread implements Runnable {
    private Socket socket;

    public ServerScoketThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            //获取客户端信息
            InputStream is = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String reply = br.readLine();//接收到客户端发送的信息
            System.out.println(socket.getInetAddress().getHostAddress() + "客户端的信息为：" +
                    reply);
            OutputStream os = socket.getOutputStream();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            bw.write("我是曾帅哥，信息已收到，请开始行动！！！");
            bw.flush();
            bw.close();
            os.close();
            br.close();
            is.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
